//
//  RegexHelper.swift
//  RegexHelper
//
//  Created by dayu on 15/6/5.
//  Copyright (c) 2015年 dayu. All rights reserved.
//

import Foundation

struct RegexHelper {
    let regex: NSRegularExpression?;
    
    init?(_ pattern: String) {
        var error: NSError?;
        regex = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error);
        if let failture = error {
            return nil;
        }
    }
    
    func match(input: String) -> Bool {
        let matches = regex?.matchesInString(input, options: nil, range: NSMakeRange(0, (input as NSString).length));
        if let result = matches {
            return result.count > 0;
        }else {
            return false;
        }
    }
}